from typing import Optional, List
from pydantic import BaseModel

class BlogBase(BaseModel):
    title: str
    type: str
    status: str
    summary: Optional[str] = None
    content: str
    tags: Optional[str] = None
    cover_image: Optional[str] = None

class BlogCreate(BlogBase):
    user_id: int

class BlogUpdate(BlogBase):
    id: int
    views: Optional[int] = None
    likes: Optional[int] = None
    comments: Optional[int] = None

class BlogInDB(BlogBase):
    id: int
    user_id: int
    views: int
    likes: int
    comments: int
    created_at: str
    updated_at: str
    
    class Config:
        orm_mode = True

class BlogResponse(BaseModel):
    id: int
    title: str
    content: str
    user_id: int
    username: str           # 👈 新增：来自关联 User 的字段
    created_at: str
    updated_at: str
    is_deleted: bool

    class Config:
        from_attributes = True  # 支持从 ORM 模型自动映射